package com.talkingdata.hadoop.guard.controller;

import com.talkingdata.hadoop.guard.bean.RmState;
import com.talkingdata.hadoop.guard.bean.YarnClusterState;
import com.talkingdata.hadoop.guard.mapper.RmMapper;
import com.talkingdata.hadoop.guard.mapper.YarnClusterMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import java.util.ArrayList;

@Controller
public class ClusterYarnInfoController {
    @Autowired
    private YarnClusterMapper yc ;

    @Autowired
    private RmMapper rm ;

    @RequestMapping("/cluster_yarn_info")
    public ModelAndView clusterYarnInfo(String clusterid){
        ModelAndView mav = new ModelAndView("cluster_yarn_info");
        System.out.println("clusterid ==> " + clusterid);
        YarnClusterState yarnClusterState = null;
        ArrayList<RmState> rmStateList = null;
        try {
            yarnClusterState = yc.selectYarnClusterStateByid(clusterid);
            rmStateList = rm.selectRMStatebyClusterId(clusterid);
        } catch (Exception e) {
            System.out.println(clusterid + " yarnClusterState or rmStates conn db failed ");
            e.printStackTrace();
        }
        System.out.println("yarnClusterState -> " + yarnClusterState.toString());
        mav.addObject("yarnClusterState" ,yarnClusterState);
        mav.addObject("rmStateList" ,rmStateList);
        return mav;
    }
}
